//
//  MineAdressDetailViewController.m
//  Mahjong
//
//  Created by KING on 16/9/8.
//  Copyright © 2016年 swift. All rights reserved.
//

#import "MineAdressDetailViewController.h"
#import "Header.h"
#import "MineListNumberTableViewCell.h"
#import "MineAdressTableViewCell.h"
#import "MineListAdressTableViewCell.h"
#import "MineAdressTitleTableViewCell.h"
#import "MineListPayTableViewCell.h"
#import "AddPhoneViewController.h"
@interface MineAdressDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *myTableView;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic,strong) UILabel *label;
@property (nonatomic, strong) UIButton *disButton;
@property (nonatomic, strong) UIButton *okButton;
@end

@implementation MineAdressDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREENH_HEIGHT-106) style:UITableViewStylePlain];
    [self.view addSubview:self.myTableView];
    self.myTableView.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1];

    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.myTableView registerNib:[UINib  nibWithNibName:@"MineListNumberTableViewCell" bundle:nil] forCellReuseIdentifier:@"numbercell"];
    [self.myTableView registerNib:[UINib nibWithNibName:@"MineListAdressTableViewCell" bundle:nil] forCellReuseIdentifier:@"adresscell"];
    [self.myTableView registerNib:[UINib  nibWithNibName:@"MineAdressTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
     [self.myTableView registerNib:[UINib  nibWithNibName:@"MineListPayTableViewCell" bundle:nil] forCellReuseIdentifier:@"paycell"];
    [self.myTableView registerNib:[UINib  nibWithNibName:@"MineAdressTitleTableViewCell" bundle:nil] forCellReuseIdentifier:@"titlecell"];
    [self createButton];
    self.navigationItem.title = @"管理详情";
    
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"nav_but_back"] style:(UIBarButtonItemStyleDone) target:self action:@selector(backAction)];
    backItem.tintColor = [UIColor grayColor];
    self.navigationItem.leftBarButtonItem = backItem;
    
}

- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)createButton{
    
    UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREENH_HEIGHT-106, SCREEN_WIDTH, 43)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:backView];
    
    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 10, 15, 15)];
    _imageView.image = [UIImage imageNamed:@"me_but_tel"];
    [backView addSubview:_imageView];
    
    _label = [[UILabel alloc] initWithFrame:CGRectMake(25, 10, 150, 22)];
    _label.text = @"联系送货员";
    [backView addSubview:_label];
    
    _disButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _disButton.frame = CGRectMake(SCREEN_WIDTH- 200, 5, 90, 35);
    _disButton.backgroundColor = [UIColor orangeColor];
    [_disButton setTitle:@"取消订单" forState:UIControlStateNormal];
    [backView addSubview:_disButton];
    _disButton.layer.cornerRadius = 5;

    _okButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _okButton.frame = CGRectMake(SCREEN_WIDTH- 100, 5, 90, 35);
    _okButton.backgroundColor = [UIColor redColor];
    [_okButton setTitle:@"付款" forState:UIControlStateNormal];
    [backView addSubview:_okButton];
    _okButton.layer.cornerRadius = 5;
    [_okButton addTarget:self action:@selector(okAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    if (self.didNum == 100) {
        _imageView.alpha = 0;
        _label.alpha = 0;
    }
    if (self.didNum == 101) {
        _imageView.alpha = 0;
        _label.alpha = 0;
        _disButton.alpha = 0;
        [_okButton setTitle:@"提醒发货" forState:UIControlStateNormal];
    }if (self.didNum == 102) {
        _disButton.alpha = 0;
        [_okButton setTitle:@"确认发货" forState:UIControlStateNormal];

    }if (self.didNum == 103) {
        _disButton.alpha = 0;
        [_okButton setTitle:@"去评价" forState:UIControlStateNormal];
    }
    
}
-(void)okAction:(UIButton *)btn{
    if (self.didNum == 103) {
        AddPhoneViewController *add = [[AddPhoneViewController alloc] init];
        [self.navigationController pushViewController:add animated:YES];
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 5;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 2;
    }
    if (section == 1) {
        return 3;
    }
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        
    if (indexPath.row == 0) {
        MineListNumberTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"numbercell"];
        return cell;
      }else {
        MineListAdressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"adresscell"];
        return cell;
          
     }
    }
    
    
    if (indexPath.section == 1) {
        MineAdressTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
        return cell;
    }
    if (indexPath.section == 2) {
        MineAdressTitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"titlecell"];
        cell.numLabel.text = @"运输方式";
        cell.timeLabel.text = @"送货";
        return cell;
    }
    if (indexPath.section == 3) {
        MineListPayTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"paycell"];
        cell.conImage.image = [UIImage imageNamed:@"but_go"];
//        cell.numLabel.text = @"支付方式";
//        cell.timeLabel.text = @"支付宝>";
        return cell;
    }
    else {
        MineAdressTitleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"titlecell"];
        cell.numLabel.text = @"买家留言:";
        cell.timeLabel.text = @"";
        return cell;
        
    }
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 40;
        }
    }
    if (indexPath.section == 2 || indexPath.section == 3 || indexPath.section == 4) {
        return 40;
    }
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 8;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
